package com.xm.dao.impl;

import com.xm.dao.RegionDao;
import com.xm.po.Region;
import com.xm.util.DButil;

import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.ArrayList;
import java.util.List;

/**
 * @author Administrator
 * @date 2020-08-07-15:34
 * @description 地址数据操作接口实现类
 */
public class RegionDaoImpl implements RegionDao {
    @Override
    public List<Region> regionList(Integer parentId) {
        List<Region> list = new ArrayList<>();
        Connection conn = DButil.getConnection();
        PreparedStatement ps = null;
        ResultSet rs = null;
        String sql = "select * from region where parentId = ?";
        try {
            ps = conn.prepareStatement(sql);
            ps.setObject(1,parentId);
            rs = ps.executeQuery();
            list = (List<Region>) DButil.getRsData(Region.class,rs);
        } catch (SQLException e) {
            e.printStackTrace();
        }finally {
            DButil.close(rs,ps,conn);
        }
        return list;
    }
}
